package rexsee.core.browser.clazz;

import java.util.Calendar;

import android.text.InputType;

public class PromptArgumentsSheet {

	public String argumentsText = "";

	public Calendar calendar = Calendar.getInstance();

	public String title = "";
	public String message = "";

	public String[] options = null;
	public String[] inputType = null;
	public String[] defaultValue = null;
	public String[] max = null;
	public String[] min = null;
	public String[] singleLine = null;

	public boolean selectCities = true;
	public boolean selectDistrictes = true;

	public boolean cancelable = false;
	public boolean returnImmediately = false;
	public boolean selectAll = false;
	public boolean continentEnable = true;
	public boolean countryEnable = true;
	public boolean provinceEnable = true;
	public boolean cityEnable = true;
	public boolean yearEnable = true;
	public boolean monthEnable = true;
	public boolean dayEnable = true;
	public boolean hour24 = true;

	public PromptArgumentsSheet parseArguments(String arguments) {
		if (arguments == null || arguments.equals("")) return this;
		argumentsText = arguments;
		String[] argus = arguments.split(";");
		try {
			for (int i = 0; i < argus.length; i++) {
				if (argus[i].indexOf("=") <= 0) continue;
				String key = argus[i].substring(0, argus[i].indexOf("=")).toLowerCase().trim();
				String value = argus[i].substring(argus[i].indexOf("=") + 1).trim();
				if (key.equals("title")) {
					title = value;
				} else if (key.equals("message")) {
					message = value;
				} else if (key.equals("options")) {
					options = value.split("\\|");
				} else if (key.equals("defaultvalue")) {
					defaultValue = value.split("\\|");
				} else if (key.equals("min")) {
					min = value.split("\\|");
				} else if (key.equals("max")) {
					max = value.split("\\|");
				} else if (key.equals("inputtype")) {
					inputType = value.split("\\|");
				} else if (key.equals("singleline")) {
					singleLine = value.split("\\|");
				} else if (key.equals("year")) {
					calendar.set(Calendar.YEAR, Integer.parseInt(value));
				} else if (key.equals("month")) {
					calendar.set(Calendar.MONTH, Integer.parseInt(value) - 1);
				} else if (key.equals("day")) {
					calendar.set(Calendar.DATE, Integer.parseInt(value));
				} else if (key.equals("hour")) {
					calendar.set(Calendar.HOUR_OF_DAY, Integer.parseInt(value));
				} else if (key.equals("minute")) {
					calendar.set(Calendar.MINUTE, Integer.parseInt(value));
				} else if (key.equals("yearenable")) {
					yearEnable = (value.equalsIgnoreCase("false")) ? false : true;
				} else if (key.equals("monthenable")) {
					monthEnable = (value.equalsIgnoreCase("false")) ? false : true;
				} else if (key.equals("dayenable")) {
					dayEnable = (value.equalsIgnoreCase("false")) ? false : true;
				} else if (key.equals("selectdistrictes")) {
					selectDistrictes = (value.equalsIgnoreCase("false")) ? false : true;
				} else if (key.equals("provinceenable")) {
					provinceEnable = (value.equalsIgnoreCase("false")) ? false : true;
				} else if (key.equals("cityenable")) {
					cityEnable = (value.equalsIgnoreCase("false")) ? false : true;
				} else if (key.equals("continentenable")) {
					continentEnable = (value.equalsIgnoreCase("false")) ? false : true;
				} else if (key.equals("countryenable")) {
					countryEnable = (value.equalsIgnoreCase("false")) ? false : true;
				} else if (key.equals("hour24")) {
					hour24 = (value.equalsIgnoreCase("false")) ? false : true;
				} else if (key.equals("cancel")) {
					cancelable = (value.equalsIgnoreCase("true")) ? true : false;
				} else if (key.equals("returnimmediately")) {
					returnImmediately = (value.equalsIgnoreCase("true")) ? true : false;
				} else if (key.equals("selectall")) {
					selectAll = (value.equalsIgnoreCase("true")) ? true : false;
				}
			}
		} catch (Exception e) {
		}
		return this;
	}

	public String getTime() {
		return calendar.get(Calendar.HOUR_OF_DAY) + ":" + calendar.get(Calendar.MINUTE);
	}
	public static int getInputType(String typeString) {
		int rtn = InputType.TYPE_CLASS_TEXT;
		if (typeString.equalsIgnoreCase("number")) {
			rtn = InputType.TYPE_CLASS_NUMBER;
		} else if (typeString.equalsIgnoreCase("decimal")) {
			rtn = InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL;
		} else if (typeString.equalsIgnoreCase("signed")) {
			rtn = InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_SIGNED;
		} else if (typeString.equalsIgnoreCase("phone")) {
			rtn = InputType.TYPE_CLASS_PHONE;
		} else if (typeString.equalsIgnoreCase("password")) {
			rtn = InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD;
		} else if (typeString.equalsIgnoreCase("email")) {
			rtn = InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS;
		} else if (typeString.equalsIgnoreCase("url")) {
			rtn = InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_URI;
		}
		return rtn;
	}

}
